package com.xuzimian.globaldemo.mq.kafka.producer;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.kafka.core.KafkaTemplate;

import java.io.IOException;

public class SpringProducer {

    @Test
    public  void sendData() throws IOException {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-kafka.xml");

        KafkaTemplate<String, String> kafkaTemplate = (KafkaTemplate) ctx.getBean("kafkaTemplate");
        kafkaTemplate.send("kafka-topic", "我的测试消息1");
        kafkaTemplate.send("kafka-topic", "我的测试消息2");
        kafkaTemplate.send("kafka-topic", "我的测试消息3");

        System.in.read();
    }

}
